<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>即时通讯平台</title>

    <link rel="stylesheet" href="css/login.css">

</head>

<body>

    <div class="container-login">
        <div class="login-dialog">
            <h2>登录</h2>
            <div class="row">
                <span>账号</span>
                <input type="text" name="userName" id="userName">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" name="password" id="password">
            </div>
            <div class="row">
                <button id="submit" onclick="login()">确认</button>
            </div>
            <div class="create">
                <button id="submit2" onclick="register()">注册</button>
            </div>
        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script>
        function login() {
            $.ajax({
                url: '/user/login',
                type: 'post',
                data: {
                    userName: $("#userName").val(),
                    password: $("#password").val()
                },
                success: function (result) {
                    if (result.code == 200 && result.data != null) {
                        location.href = "client.html";
                    }
                    else if (result.code == 200 && result.data == null) {
                        alert("密码错误");
                    }
                    else if (result.code == -1) {
                        alert(result.error);
                    }
                }
            })
            
        }
        function register() {
            location.assign("register.html");
        }
    </script>
</body>

</html>